package com.voxel.sense.infomsg.module.task.manager;

import com.example.com.common.factory.data.DataSource;
import cyy.example.com.facotry.constants.Constants;
import cyy.example.com.facotry.model.api.response.MyTaskListInfoEntity;
import com.voxel.sense.infomsg.net.helper.TaskManagerNetHelper;
import com.voxel.sense.infomsg.module.task.BaseTaskPresenter;

import java.util.List;

/**
 * 任务管理
 * Created by ChenYiYao on 2018/3/22.
 */

public class TaskManagerPresenter extends BaseTaskPresenter<TaskManagerContract.View>
        implements TaskManagerContract.Presenter, DataSource.Callback<MyTaskListInfoEntity> {


    public TaskManagerPresenter(TaskManagerContract.View view) {
        super(view);
    }

    @Override
    public void loadData() {
        netloadData(1);
    }

    @Override
    public void loadMoreData() {
        netloadData(CURRENT_PAGE_SIZE + 1);
    }


    private void netloadData(int numb) {
        TaskManagerNetHelper.queryMyTaskInfoList(numb, Constants.TASK_ALL_TYPE, mSortType,
                (List<String>) mQueryMap.get(Constants.TYPE_AREA), (List<String>)
                        mQueryMap.get(Constants.TYPE_IDUSTRY), this);
    }

    @Override
    public void onDataLoaded(MyTaskListInfoEntity data, int reqId) {
        if (mView == null) {
            return;
        }
        mView.dimissLoading();
        if (data != null) {
            CURRENT_PAGE_SIZE = data.getBody().getPageNum();
            loadDataComplete(data.getBody().getTaskInfoList());
        } else {
            LoadDataFailure();
        }
    }

    @Override
    public void onDataNotAvailable(String strRes, int reqId) {
        if (mView == null) {
            return;
        }
        mView.dimissLoading();
        LoadDataFailure();
        mView.showEmptyView(strRes,true);
    }
}
